package com.xin.web;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CookieServlet extends BaseServlet2{
    protected void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if("zhangsan".equals(username)&&"123456".equals(password)){
            Cookie cookie=new Cookie("usernamek",username);
            cookie.setMaxAge(60*60);
            resp.addCookie(cookie);
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }
    }
    protected void testpath(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("过来了");
        Cookie cookie=new Cookie("path1","zhangsan");
        //cookie.setPath(req.getContextPath()+"/test");
        resp.addCookie(cookie);
    }
}
